package cn.iocoder.yudao.module.xhyy.dal.mysql.beikao;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.xhyy.controller.app.beikao.vo.AppBeikaoPageReqVO;
import cn.iocoder.yudao.module.xhyy.dal.dataobject.beikao.BeikaoDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.xhyy.controller.admin.beikao.vo.*;

/**
 * 高三资源 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface BeikaoMapper extends BaseMapperX<BeikaoDO> {

    default PageResult<BeikaoDO> selectPage(BeikaoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BeikaoDO>()
                .eqIfPresent(BeikaoDO::getYear, reqVO.getYear())
                .eqIfPresent(BeikaoDO::getType, reqVO.getType())
                .likeIfPresent(BeikaoDO::getResourceName, reqVO.getResourceName())
                .betweenIfPresent(BeikaoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BeikaoDO::getId));
    }

    default PageResult<BeikaoDO> selectPage(AppBeikaoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BeikaoDO>()
                .eqIfPresent(BeikaoDO::getYear, reqVO.getYear())
                .eqIfPresent(BeikaoDO::getType, reqVO.getType())
                .likeIfPresent(BeikaoDO::getResourceName, reqVO.getResourceName())
                .betweenIfPresent(BeikaoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BeikaoDO::getId));
    }

    default List<Map<String, Object>> selectYears(Integer type) {
        QueryWrapper<BeikaoDO> queryWrapper = new QueryWrapper<>();

        // 根据字段查询
        queryWrapper.eq("type", type);

        // 按year字段分组，只查询year字段
        queryWrapper.select("year").groupBy("year")
                .orderByAsc("year");

        // 执行查询，返回Map列表，包含年份信息
        return selectMaps(queryWrapper);
    }
}